//
// Created by lenovo on 2023/12/24.
//
#include<bits/stdc++.h>
using namespace std;
struct code
{
    int pi;
    int ai;
}arr[5003];
bool cmp(code a, code b)
{
    return a.pi < b.pi;
}
int main()
{
    int n = 0,m = 0;
    cin >> n >>  m;
    for(int i  = 0;i < m;i++){
        cin >> arr[i].pi >> arr[i].ai;
    }
    sort (arr , arr + m,cmp);
    int ans = 0, cpy = 0;
    for(int i = 0;i < m;i++)
    {
      if(n > arr[i].ai)
      {
          ans += arr[i].pi * arr[i].ai;
          n -= arr[i].ai;
      }
      else
      {
          ans += n * arr[i].pi;
          break;
      }

    }
   cout << ans;
    return 0;
}